package com.htiiot.hbase;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;


public class Cmd {
	
	public static String zk = null;
	public static String table = null;
	public static String uidTable = null;
	
	public static void parserCmd(String[] args) {
		Options options = new Options();
		options.addOption("h", "help", false, "Print this usage information");
		options.addOption("z", "zookeeper", true, "The connection info of zk,like:master.htdata.com:2181");
		options.addOption("t", "table", true, "The table to save data");
		options.addOption("u", "uidTable", true, "The table to save uid");
		CommandLine cmd=null;
		CommandLineParser parser = new BasicParser();
		try {
			cmd = parser.parse(options, args);
		} catch (org.apache.commons.cli.ParseException e1) {
			HelpFormatter formatter = new HelpFormatter();
			formatter.printHelp("create tsdb table", options);
			e1.printStackTrace();
			System.exit(0);
		}
		if(cmd.hasOption("h")){
			HelpFormatter formatter = new HelpFormatter();
			formatter.printHelp("OLDStore", options);
			System.exit(0);
		}
		
		if(cmd.hasOption("z")){
			zk = cmd.getOptionValue("z");
		}
		if(cmd.hasOption("t")){
			table = cmd.getOptionValue("t");
		}
		if(cmd.hasOption("u")){
			uidTable = cmd.getOptionValue("u");
		}
		
		if(zk==null){
			System.out.println("zookeeper not config");
			System.exit(0);
		}
		if(table==null){
			System.out.println("data table not config");
			System.exit(0);
		}
		if(uidTable==null){
			System.out.println("uid table not config");
			System.exit(0);
		}
		
		
	}

}
